package com.norteksoft.erm.model;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * 数据资源定义
 * 
 * @hibernate.class table="ERM_DATARESOURCE"
 * @author Jiffy
 * 
 */
public class DataResource extends BaseObject {

	private static final long serialVersionUID = 1479838285970016055L;

	public static final String TYPE_SUITE = "suite";

	public static final String TYPE_CLAZZ = "clazz";

	public static final String TYPE_RDB = "rdb";// 关系数据库

	public static final String TYPE_TORNADO = "tornado";// 龙卷风全文索引

	private Long OID = new Long(-1);// OID

	private String name;// 数据资源名称

	private String clazzName;// 数据资源类名（作为数据资源的唯一标识）

	private String dataResourceType;//

	private String isAvailable;// 数据资源是否保护

	private WebModule webModule;// 所属子系统

	private Set dataDimensions = new HashSet();// 数据域条件类型

	private Set dataOperations = new HashSet();// 数据操作类型

	private Set dataRoles = new HashSet();// 数据角色类型

	private String memo;

	// 保留操作类型
	public static Set DEFAULT_OPERATIONS = null;

	static {
		if (DEFAULT_OPERATIONS == null) {
			DEFAULT_OPERATIONS = new TreeSet(Arrays
					.asList((new DataOperation[] { DataOperation.CREATE,
							DataOperation.SEARCH, DataOperation.VIEW,
							DataOperation.MODIFY, DataOperation.DELETE,
							DataOperation.LIST })));
		}
	}

	public int hashCode() {
		return new HashCodeBuilder().append(OID).append(name).append(clazzName)
				.append(dataResourceType).append(isAvailable).append(memo)
				.toHashCode();
	}

	/**
	 * @hibernate.id column="OID" unsaved-value="-1" type="long"
	 * @hibernate.generator class="sequence"
	 * @hibernate.param name="sequence" value="ERM_SEQUENCE"
	 */

	public Long getOID() {
		return OID;
	}

	public void setOID(Long oid) {
		OID = oid;
	}

	/**
	 * @hibernate.property column="NAME" length="60" type="string"
	 *                     not-null="true"
	 * @return String
	 */
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @hibernate.property column="CLAZZNAME" length="100" type="string"
	 * @return String
	 */
	public String getClazzName() {
		return clazzName;
	}

	public void setClazzName(String clazzName) {
		this.clazzName = clazzName;
	}

	/**
	 * @hibernate.many-to-one name="webModule" column="WEBMODULEID"
	 *                        class="com.norteksoft.erm.model.WebModule"
	 */
	public WebModule getWebModule() {
		return webModule;
	}

	public void setWebModule(WebModule webModule) {
		this.webModule = webModule;
	}

	/**
	 * @hibernate.set lazy="false" inverse="true" cascade="all-delete-orphan"
	 *                order-by="name asc"
	 * @hibernate.key column="DATARESOURCEOID"
	 * @hibernate.one-to-many class="com.norteksoft.erm.model.DataDimension"
	 * @return Set
	 */
	public Set getDataDimensions() {
		return dataDimensions;
	}

	public void setDataDimensions(Set dataDimensions) {
		this.dataDimensions = dataDimensions;
	}

	/**
	 * @hibernate.set lazy="false" inverse="true" cascade="all-delete-orphan"
	 *                order-by="mask asc"
	 * @hibernate.key column="DATARESOURCEOID"
	 * @hibernate.one-to-many class="com.norteksoft.erm.model.DataOperation"
	 * @return Set
	 */
	public Set getDataOperations() {
		return dataOperations;
	}

	public void setDataOperations(Set dataOperations) {
		this.dataOperations = dataOperations;
	}

	/**
	 * @hibernate.property column="MEMO" length="1000" type="string"
	 * @return String
	 */
	public String getMemo() {
		return memo;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}

	/**
	 * @hibernate.set lazy="false" inverse="true" cascade="all-delete-orphan"
	 *                order-by="OID asc"
	 * @hibernate.key column="DATARESOURCEOID"
	 * @hibernate.one-to-many class="com.norteksoft.erm.model.DataRole"
	 * @return Set
	 */

	public Set getDataRoles() {
		return dataRoles;
	}

	public void setDataRoles(Set dataRoles) {
		this.dataRoles = dataRoles;
	}

	/**
	 * @hibernate.property column="DATARESOURCETYPE" length="10" type="string"
	 * @return String
	 */

	public String getDataResourceType() {
		return dataResourceType;
	}

	public void setDataResourceType(String dataResourceType) {
		this.dataResourceType = dataResourceType;
	}

	public boolean getHasDataRole() {
		return CollectionUtils.isNotEmpty(dataRoles);
	}

	/**
	 * @hibernate.property column="ISAVAILABLE" length="10" type="string"
	 * @return String
	 */
	public String getIsAvailable() {
		return isAvailable;
	}

	public void setIsAvailable(String isAvailable) {
		this.isAvailable = isAvailable;
	}

}
